﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


/// <summary>
///实现专辑功能的类
/// </summary>
public class Special
{
    private int specialID;//专辑ID，唯一标志一个专辑
    private String specialName;
    private String ownerID;//创建专辑的人
    private String url; //专辑封面图片路径（预留）
    private String introduction;//简介
    private String tag;//专辑标签，搜索使用
    private int[] movieMembers;//专辑内包含的视频的ID
    private DateTime createTime;

    public Special()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }

    //把movieMembers数组转换成字符串存储
    public String toMovieMember(int[] movieMembers)
    {
        String movieMember = "";
        for (int i = 0; i < movieMembers.Length - 1; i++)
        {
            movieMember += movieMembers[i] + ",";
        }
        movieMember += movieMembers[movieMembers.Length - 1];
        return movieMember;
    }

    //添加专辑
    public bool add(String specialName, String ownerID, String url, String introduction, String tag)
    {
        String sql = "insert into tb_Special(specialName,ownerID,url,introduction,tag,createDateTime) values('"
            + specialName + "','" + ownerID + "','" + url + "','" + introduction + "','" + tag + "','" + DateTime.Now + "')";
        SqlExecutor myExec = new SqlExecutor();
        return myExec.UpdateCmd(sql);
    }

    public bool delete(int specialID)
    {
        SqlExecutor myExec = new SqlExecutor();
        return myExec.UpdateCmd("delete from tb_Special where specialID='" + specialID + "'");
    }

    //更新专辑信息
    public bool Update(int specialID, String specialName, String ownerID, String url, String introduction, String tag)
    {
        String sql = "update tb_Special set specialName='" + specialName + "',ownerID='" + ownerID + "',url='" + url
            + "',introduction'" + introduction + "',tag='" + tag + "' where specialID='" + specialID + "'";
        SqlExecutor myExec = new SqlExecutor();
        return myExec.UpdateCmd(sql);
    }

    //修改专辑中的视频
    public bool updateMovie(int specialID,int[] movieMembers)
    {
        String movieMember=toMovieMember(movieMembers);
        SqlExecutor myExec = new SqlExecutor();
        return myExec.UpdateCmd("update tb_Special set movieMembers='"+movieMember+"' where specialID='"+specialID+"'");
    }

    public int SpecialID
    {
        get { return specialID; }
        set { specialID = value; }
    }

    public String SpecialName
    {
        get { return specialName; }
        set { specialName = value; }
    }

    public String OwnerID
    {
        get { return ownerID; }
        set { ownerID = value; }
    }

    public DateTime CreateTime
    {
        get { return createTime; }
        set { createTime = value; }
    }

    public String Introduction
    {
        get { return introduction; }
        set { introduction = value; }
    }

    public String Tags
    {
        get { return tag; }
        set { tag = value; }
    }

    public int[] MovieMembers
    {
        get { return movieMembers; }
        set { movieMembers = value; }
    }

}

